//
//  AFNConnect.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/6/24.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "AFNConnect.h"

@implementation AFNConnect

+(void)AFNConnectWithUrl:(NSString *)urlStr key:(NSString *)key connectBlock:(void (^)(id))myBlock
{
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    //[manager.requestSerializer setValue:@"iPhone; iPhone OS 8.3; zh_CN" forHTTPHeaderField:@"User-Agent"];
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        //            NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        
        
        NSArray *array = responseObject[key];
        //NSLog(@"%@",array);
        myBlock(array);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        
    }];

    
}

@end
